var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
Page({
  data: {
    imgUrl: globalData.imgUrl,
    pageNo: 1,
    pageSize: 10,
    totalPage: 1,
    list: [],
  },
  onLoad: function (options) {
    this.list();
  },
  list: function (options) {
    let that = this;
    let params = new Object();
    params.pageNo = this.data.pageNo;
    params.pageSize = this.data.pageSize;
    commonUtil.showLoading("请稍等...");
    let openId = wx.getStorageSync("openidKey");
    let sid = wx.getStorageSync("JSESSIONID");
    console.log("header:openId:" + openId + ",sid:" + sid);
    wx.request({
      header: { "openId": openId, "sid": sid, "content-Type": "application/x-www-form-urlencoded" },
      url: httpsUrl + "/businessManage/orderRecord",
      dataType: "json",
      method: "POST",
      data: params,
      success: function (res) {
        commonUtil.hideLoading();
        var res = res.data;
        console.log(JSON.stringify(res));
        if (res.result == 0) {
          // that.setData({ list: res.data.list })
          let rows = res.data.list;
          that.setData({ totalPage: res.data.totalPage })
          if (rows != null && rows.length > 0) {
            for (let i = 0; i < rows.length; i++) {
              if (!commonUtil.isEmpty(rows[i].receivable)) {
                rows[i].receivable = rows[i].receivable.toFixed(2);
              }
              //1,待支付 2,待使用 3,待评价 4,已完成
              if (rows[i].status == 1) { rows[i].statusstr = '待支付' }
              else if (rows[i].status == 2) { rows[i].statusstr = '待使用' }
              else if (rows[i].status == 4) { rows[i].statusstr = '已完成' }
            }
          }
          if (that.data.pageNo == 1) {
            that.setData({ list: rows })
          } else {
            var list = that.data.list;
            list = list.concat(rows);
            that.setData({ list: list })
          }
        }
      }
    })
  },
  info: function (e) {
    let id = e.currentTarget.id;
    let list = this.data.list;
    let row = list[id];
    wx.setStorageSync("orderInfo", row);
    wx.navigateTo({
      url: '../orderInfo/orderInfo',
    })
  },
  onReachBottom: function () {
    let pageNo = this.data.pageNo;
    pageNo = pageNo + 1;
    if (pageNo > this.data.totalPage) {
      commonUtil.showSuccessToast("没有更多啦~");
      return;
    } else {
      this.setData({ pageNo: pageNo })
      this.list();
    }
  },
})